extends ../../layout.pug

block content
  - const d = pageInfo.data
  - runNumber = iteration
  - const daTitle = daurlAlias ? daurlAlias : daurl
  - const downloadName = (daTitle + '-' + runNumber + '-' + options.browser + '-' + timestamp).replace(/(https?\:\/\/)|( )|(:)/ig, '')

  h1 Run #{runNumber} summary
  h5.url
    a(href=daurl) #{decodeURIComponent(daTitle)}

  include ../includes/pageRunInfo

  if d.browsertime && d.browsertime.run
    b #{d.browsertime.run.title}
    p !{d.browsertime.run.description}

  p
    .large All runs:&nbsp;
      each val, index in runPages
        - value = Number(index) + 1
        if (runNumber === value)
          span.label.normal.info #{value}
        else
          a(href='./' + value + '.html') #{value}
        if (value !== Object.keys(runPages).length)
          | &nbsp;-
          |

  if d.browsertime && d.browsertime.run.errors  && d.browsertime.run.errors.length > 0
    .errors
      b Errors
      ul
        each error in d.browsertime.run.errors
          li #{error} 

  .index-link
    a.button.button--primary(href=urlLink) Back to summary

  include ./tabs.pug

  #tabSections
    section#summary-panel
      h2 Summary
      .row
        .one-half.column
          table
            tr
              th Metric
              th Value
            - performanceScore = get(d, 'coach.run.advice.performance.score')
            if performanceScore
              tr
                td Performance score
                td #{performanceScore}
            - totalTransferSize = get(d, 'pagexray.run.transferSize')
            if totalTransferSize
              tr
                td Total page size
                td #{h.size.format(totalTransferSize)}
            - requests = get(d, 'pagexray.run.requests')
            if (requests)
              tr
                td Requests
                td #{requests}
            - ttfb = get(d, 'browsertime.run.timings.pageTimings.backEndTime') 
            if ttfb
              tr
                td TTFB
                td #{h.time.ms(ttfb)}
            - fullyLoaded = get(d, 'browsertime.run.fullyLoaded') 
            if fullyLoaded
              tr
                td Fully Loaded
                td #{h.time.ms(fullyLoaded.toFixed(0))}
            - firstVisualChange = get(d, 'browsertime.run.visualMetrics.FirstVisualChange')
            - firstPaint = get(d, 'browsertime.run.timings.firstPaint')
            if firstVisualChange
              tr
                td First Visual Change
                td #{h.time.ms(firstVisualChange)}
            else if firstPaint
              tr
                td First Paint
                td #{h.time.ms(firstPaint)}  
            - fcp = get(d, 'browsertime.run.timings.paintTiming["first-contentful-paint"]') 
            if fcp
              tr
                td FCP
                td #{h.time.ms(fcp)}         
            - lcp = get(d, 'browsertime.run.timings.largestContentfulPaint.renderTime')
            if lcp
              tr
                td LCP
                td #{h.time.ms(lcp)}
            - cls = get(d, 'browsertime.run.pageinfo.layoutShift')
            if cls || cls === 0
                tr
                  td CLS
                  td #{cls}
            - tbt = get(d, 'browsertime.run.cpu.longTasks.totalBlockingTime')
            if tbt  
              tr
                td Total Blocking Time
                td #{h.time.ms(tbt)}
            - mpFID = get(d, 'browsertime.run.cpu.longTasks.maxPotentialFid')
            if mpFID
              tr
                td Max Potential FID
                td #{h.time.ms(mpFID)}
            - longTasks = get(d, 'browsertime.run.cpu.longTasks.tasks')
            if longTasks
              tr
                td CPU long tasks
                td #{longTasks}
            - maxLongTask= get(d, 'browsertime.run.cpu.longTasks.durations.max') 
            if maxLongTask 
              tr
                td CPU longest task duration
                td #{h.time.ms(maxLongTask)}
            - speedIndex = get(d, 'browsertime.run.visualMetrics.SpeedIndex')
            if speedIndex
              tr
                td Speed Index
                td #{h.time.ms(speedIndex)}
            - visualComplete85 = get(d, 'browsertime.run.visualMetrics.VisualComplete85')
            if visualComplete85
              tr
                td Visual Complete 85%
                td #{h.time.ms(visualComplete85)}
            - visualComplete99 = get(d, 'browsertime.run.visualMetrics.VisualComplete99')
            if visualComplete99
              tr
                td Visual Complete 99%
                td #{h.time.ms(visualComplete99)}  
            - lastVisualChange = get(d, 'browsertime.run.visualMetrics.LastVisualChange')
            if lastVisualChange
              tr
                td Last Visual Change
                td #{h.time.ms(lastVisualChange)}
            if !d.browsertime && d.webpagetest
              tr
                td Render (first view)
                td #{d.webpagetest.run.firstView.render}
              tr
                td Speed Index (first view)
                td #{d.webpagetest.run.firstView.SpeedIndex}
              tr
                td Visual Complete 85% (first view)
                td #{d.webpagetest.run.firstView.visualComplete85}
              tr
                td Last Visual Change (first view)
                td #{d.webpagetest.run.firstView.lastVisualChange}
              tr
                td Requests
                td #{d.webpagetest.run.firstView.requestsFull}

        .one-half.column
            if !d.browsertime && d.webpagetest
              - screenshotName = 'data/screenshots/wpt-' + iteration + '-firstView.png'
              a(href=screenshotName)
                img.screenshot(src=screenshotName, alt='Screenshot')
            else if hasScreenShots
              - screenshotName = 'data/screenshots/' + iteration + '/afterPageCompleteCheck.' + screenShotType
              - const width = options.mobile ? 150 : '100%';
              a(href=screenshotName)
                img.screenshot(src=screenshotName, width=width, alt='Screenshot')
      .downloads
        include ./downloads.pug
        include ./tcpdump.pug
    if d.browsertime && d.browsertime.run && d.browsertime.run.har
      section#waterfall-panel
        include ../waterfall/index.pug

    if options.browsertime.video
      section#video-panel
        include ../video/index.pug

    if (options.browsertime.video || options.browsertime.visualMetrics) && options.videoParams.createFilmstrip || options.browsertime.chrome && options.browsertime.chrome.enableTraceScreenshots
      section#filmstrip-panel
        include ../filmstrip/index.pug        

    if d.coach && d.coach.run
      section#coach-panel
        include ../coach/index.pug

    if d.browsertime && d.browsertime.run
      section#metrics-panel
        include ../metrics/index.pug

    if d.pagexray && d.pagexray.run
      section#pagexray-panel
        include ../pagexray/index.pug

    if options.cpu || (options.browsertime && options.browsertime.chrome && options.browsertime.chrome.collectLongTasks) || (options.browsertime && options.browsertime.firefox && options.browsertime.firefox.geckoProfiler)
      section#cpu-panel
        include ../cpu/index.pug     
    
    if d.thirdparty && d.thirdparty.run
      section#thirdparty-panel
        include ../thirdparty/index.pug

    if d.browsertime && d.browsertime.run
      section#screeenshots-panel
        include ../screenshots/index.pug

    each pageRun in pageRuns
      - const panelName = pageRun.id + '-panel'
      section(id=panelName)
        p !{pugs[pageRun.id]}
